const search = (nums, target) => {
  let l = 0, r = nums.length - 1
  while (l <= r) {
    const mid = Math.floor((r - l) / 2) + l
    nums.sort((a, b) => a - b)
    if (nums[mid] === target) {
      return mid
    } else if (nums[mid] > target) {
      r = mid - 1
    } else {
      l = mid + 1
    }
  }
  return -1
};

console.log(search([-1, 0, 3, 5, 9, 12], 9));